package cn.jimjim.framework.code.generator.common;

import lombok.NonNull;
import org.jooq.Condition;
import org.jooq.TableField;
import org.jooq.impl.DSL;

import java.util.Set;


/**
 * @author jim
 * @date 2019-03-14
 */
@SuppressWarnings("unchecked")
public abstract class AbstractCriteria<T> {

    private Integer pageNum = 1;

    private Integer pageSize = 20;

    private transient Condition condition = DSL.condition(true);

    public Condition getCondition() {
        return condition;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    protected void equal(TableField column, @NonNull Object value) {
        condition = condition.and(column.eq(value));
    }

    protected void orEqual(TableField column, @NonNull Object value) {
        this.condition = condition.or(column.eq(value));
    }

    protected void notEqual(TableField column, @NonNull Object value) {
        this.condition = condition.and(column.notEqual(value));
    }

    protected void orNotEqual(TableField column, @NonNull Object value) {
        this.condition = condition.or(column.notEqual(value));
    }

    protected void lessThan(TableField column, @NonNull Object value) {
        this.condition = condition.and(column.lessThan(value));
    }

    protected void orLessThan(TableField column, @NonNull Object value) {
        this.condition = condition.or(column.lessThan(value));
    }

    protected void lessThanEqual(TableField column, @NonNull Object value) {
        this.condition = condition.and(column.lessOrEqual(value));
    }

    protected void orLessThanEqual(TableField column, @NonNull Object value) {
        this.condition = condition.or(column.lessOrEqual(value));
    }

    protected void greaterThan(TableField column, @NonNull Object value) {
        this.condition = condition.and(column.greaterThan(value));
    }

    protected void orGreaterThan(TableField column, @NonNull Object value) {
        this.condition = condition.or(column.greaterThan(value));
    }

    protected void greaterThanEqual(TableField column, @NonNull Object value) {
        this.condition = condition.and(column.greaterOrEqual(value));
    }

    protected void orGreaterThanEqual(TableField column, @NonNull Object value) {
        this.condition = condition.or(column.greaterOrEqual(value));
    }

    protected void like(TableField column, @NonNull String value) {
        this.condition = condition.and(column.like(value));
    }

    protected void orLike(TableField column, @NonNull String value) {
        this.condition = condition.or(column.like(value));
    }

    protected void notLike(TableField column, @NonNull String value) {
        this.condition = condition.and(column.notLike(value));
    }

    protected void orNotLike(TableField column, @NonNull String value) {
        this.condition = condition.or(column.notLike(value));
    }

    protected void in(TableField column, @NonNull Set<?> values) {
        this.condition = condition.and(column.in(values));
    }

    protected void in(TableField column, @NonNull Object... values) {
        this.condition = condition.and(column.in(values));
    }

    protected void orIn(TableField column, @NonNull Set<?> values) {
        this.condition = condition.or(column.in(values));
    }

    protected void orIn(TableField column, @NonNull Object... values) {
        this.condition = condition.or(column.in(values));
    }

    protected void notIn(TableField column, @NonNull Set<?> values) {
        this.condition = condition.and(column.notIn(values));
    }

    protected void notIn(TableField column, @NonNull Object... values) {
        this.condition = condition.and(column.notIn(values));
    }

    protected void orNotIn(TableField column, @NonNull Set<?> values) {
        this.condition = condition.or(column.notIn(values));
    }

    protected void orNotIn(TableField column, @NonNull Object... values) {
        this.condition = condition.or(column.notIn(values));
    }

}
